<?php
header("Access-Control-Allow-Origin:*");
require_once('dbServerConnect.php');
$con = new DB();
$link = $con->mySqlServer();
// 根据文件名称删除文件
$fileName = $_GET['fileName'];
$dir = './upload/'.$fileName;
$userName = $_GET['userName'];
if ($link && $userName) {
    $sql = "select * from login where username='$userName' and power='super'";
    $excute = mysqli_query($link,$sql) or die(mysqli_error($link));
    $result = mysqli_fetch_row($excute);
    if ($result) {
        if (file_exists($dir)) {
            if(unlink($dir)) {
                response(1,'删除成功');
            } else {
                response(0,'删除失败');
            }
        } else {
            response(0,'目录不存在!');
        }
    } 
    else {
        response(0, '你没有【权限】删除');
    }
}


function response ($staus, $msg) {
    $res = array('status' => $staus, 'msg' => $msg);
    echo json_encode($res);
}

